Component({
  properties: {
    list: Object,
    keyName: String,
    activeColor: String,
    isSearch: Boolean,
    idx: {
      type: String,
      value: 0,
    },
    placeholder: {
      type: String,
      value: '',
    },
    isScroll: {
      type: Boolean,
      value: true,
    },
    bgcolor: {// 背景色
      type: String,
      value: '',
    },
    isfixed: {// 是否固定定位
      type: Boolean,
      value: false,
    },
    fixTop: {// 固定定位位置
      type: Number,
      value: 0,
    },
    className: {
      type: String,
      value: '',
    },
  },
  data: {
    _showSearchBox: false,
    _searchVal: '',
    searchFocus: true,
  },
  methods: {
    _switchTab(e) {
      const idx = e.currentTarget.dataset.idx;
      const D = this.data;
      if (Number(D.idx) === Number(idx)) return;
      this.setData({
        idx,
      }, () => {
        this.triggerEvent('switchTab', {
          idx,
          obj: D.list[idx],
        });
      });
    },
    _navmore() {
      this.triggerEvent('navmore');
    },
    _onSearch() {
      this.triggerEvent('search', {
        keyword: this.data._searchVal,
      });
    },
    _setSearchVal(e) {
      this.setData({
        _searchVal: e.detail.value,
      });
    },
    _clearSearchVal() {
      this.setData({
        _showSearchBox: false,
      });
      this.triggerEvent('search', {
        keyword: '',
      });
    },
    showSearchBar() {
      this.setData({
        _showSearchBox: !this.data._showSearchBox,
        searchFocus: true,
      });
    },
  },
});
